package com.expensetracker.dto;

import static javax.persistence.GenerationType.SEQUENCE;

import java.io.Serializable;
import java.util.List;
import java.util.SortedSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.IndexColumn;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;

@Entity
@Table(name = "expense_type")
public class ExpenseType implements Serializable {

	private static final long serialVersionUID = 6196386007843378529L;
	private Long id;
	private ExpenseType parent;
	private String name;
	private String description;
	private List<ExpenseType> children;

	 @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
	public List<ExpenseType> getChildren() {
		return children;
	}

	public void setChildren(List<ExpenseType> children) {
		this.children = children;
	}

	@SequenceGenerator(name = "generator", sequenceName = "expense_type_id_seq")
	@Id
	@GeneratedValue(strategy = SEQUENCE, generator = "generator")
	@Column(name = "ID", unique = true, nullable = false)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}


	@ManyToOne()
	@JoinColumn(name="PARENT_TYPE")
	public ExpenseType getParent() {
		return parent;
	}

	
	public void setParent(ExpenseType parent) {
		this.parent = parent;
	}

	@Column(name = "NAME", nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "DESCRIPTION", nullable = true)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
